package com.freecat.xmqgct.mvp.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.freecat.xmqgct.R;
import com.freecat.xmqgct.mvp.bean.TestDataBean;

import java.util.List;


/**
 * lj
 * 2019/5/20
 * 商城筛选
 */

public class TestScreenAdapter extends BaseAdapter {
    private Context context;
    private List<TestDataBean> list;

    public TestScreenAdapter(Context context, List<TestDataBean> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_testsc, parent, false);
            holder = new ViewHolder();
            holder.name = convertView.findViewById(R.id.tv_screen_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (list.get(position).getState()) {
            holder.name.setTextColor(context.getResources().getColor(R.color.white));
            holder.name.setBackgroundResource(R.drawable.shape_confirm_button);
        } else {
            holder.name.setTextColor(context.getResources().getColor(R.color.theme_color));
            holder.name.setBackgroundResource(R.drawable.shape_cancel_button);
        }

        holder.name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                list.get(position).setState(!list.get(position).getState());
                notifyDataSetChanged();
            }
        });

        holder.name.setText(list.get(position).getName());

        return convertView;
    }

    private class ViewHolder {
        TextView name;

    }


}